<?php
if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je");
	$le=new go_sql();
	$le->connect();
}

$txt = json_encode($_REQUEST);
$ip = GetIP();
logfile($txt."|".$ip,'who_get_pwd');

$m_permissions = array('pzp01','fl02','xh03');
$member = $_REQUEST['member'];
if(!in_array($member, $m_permissions)) exit('{"msg":"非法人员不得访问"}');



$account  = $_REQUEST['account'] + 0;
if(strlen($account)!=6) exit('{"msg":"请输入6位数正确账号"}');



$sel = "select id,dtype,dname from pft_member where account='$account' limit 1";
$GLOBALS['le']->query($sel);
if(!$GLOBALS['le']->fetch_assoc()) exit('{"msg":"无此账号信息"}');
$id = $GLOBALS['le']->f('id');
$dtype = $GLOBALS['le']->f('dtype');
$dname = $GLOBALS['le']->f('dname');

$_SESSION = array( 
	'sid' 		=> $id,
	'memberID' 	=> $id,
	'dtype'		=> $dtype,
	'sdtype'	=> $dtype,
	'account'	=> $account,
	'saccount'	=> $account,
	'dname'		=> $dname
);
exit;


function logfile($word,$path){
	$filepath= '/var/www/html/new/d/logs/api/who_get_pwd/'.$path.'.txt';
	$word = date("Y-m-d H:i:s")."|".$word;
	if(file_exists($filepath)){
		$maxsize  = 1024*1024*10;
		$filesize = filesize($filepath);
		$filetype = end(explode(".",$filepath));
		$filename = substr($filepath,0,strpos($filepath,'.'));
		if($filesize>$maxsize)
		rename($filepath, $filename.'_'.date('YmdHis').'.'.$filetype);
	}
	$fp = fopen($filepath,"a");
	flock($fp, LOCK_EX);
	fwrite($fp,$word."\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}

function GetIP(){
	if(!empty($_SERVER["HTTP_CLIENT_IP"])){
		$cip = $_SERVER["HTTP_CLIENT_IP"];
	}elseif(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
		$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
	}elseif(!empty($_SERVER["REMOTE_ADDR"])){
		$cip = $_SERVER["REMOTE_ADDR"];
	}
	else{
	  $cip = "无法获取！";
	}
	return $cip;
}
?>